/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package br.com.jr2tecnologia;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Random;
import java.util.logging.Logger;


/**
 *
 * @author ronildo
 */
public class SMSUtil {

    private static final Logger logger = LoggerFactory.getLogger();

    public static final String DATE_NOWSMS = "yyyyMMddhhmmss";
    public static final String DATE_BR = "dd/MM";

    public static Date parseDate(String time, String pattern){
        try{
            return new SimpleDateFormat(pattern).parse(time);
        }catch(Exception ex){
            throw new RuntimeException();
        }
    }

    public static String formatDate(Date date, String pattern){
        return new SimpleDateFormat(pattern).format(date);
    }

    public static String arrangesPhone(String arg){
        arg = arg.trim();
        try{
            Long.parseLong(arg);
        }catch(NumberFormatException ex){
            logger.info("This phone number "+arg+" is not a number");
            return null;
        }

        if(arg.length() == 12){
            return arg;
        }else if (arg.length() == 10){
            return "55"+arg;
        }else if (arg.length() == 8){
            return "5511"+arg;
        }else{
            logger.info("This phone number "+arg+" is very small");
            return null;
        }
    }

    public static String makeActivationKey(){
        int len = 64;
        char[] chart ={'0','1','2','3','4','5','6','7','8','9','a','b','c','d',
        'e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v',
        'w','x','y','z','A','B','C','D','E','F','G','H','I','J','K','L','M','N',
        'O','P','Q','R','S','T','U','V','W','X','Y','Z'};
        char[] senha= new char[len];

        int chartLenght = chart.length;
        Random rdm = new Random();

        for (int i=0; i<len; i++)
            senha[i] = chart[rdm.nextInt(chartLenght)];
        return new String(senha);
    }
}